home *** CD-ROM | disk | FTP | other *** search
/ Inside Mac Games Volume 3 #12 / IMG 33 Dec 1995.iso / IMG December 1995 / IMG December 1995.rsrc / TEXT_143.txt < prev    next >
Text File  |  1995-12-06  |  12KB  |  114 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17. by Jamie McCornack
  18.  
  19.  
  20. Small Sounds
  21.  
  22. One common and terribly annoying shareware feature is Big Sound. You download a 900K game from your favorite online service (and it takes a while, and you're paying for the time), save it on the 20 meg currently free on your GameHD partition, and discover you really got a 200K game with a 700K ‚Äòsnd‚Äô resource for the splash screen background music. Grumble. Are you going to save that game? Are you going to recommend it to your friends? Are you going to send in the requested $15 registration fee? Neither am I.
  23.  
  24. I may take particular offense if that 30-second background clip came off the Tank Girl soundtrack CD. I figure I‚Äôm paying by the byte, so the shareware author is charging me $11.67 for 30 seconds of music and $3.33 for the rest of the game, and I could take my $11.67 down to Tower Records and buy the whole album! Oh yeah, and I doubt the shareware author is paying any licensing fee to Stomp, and the tone is kind of flat, like the CD is playing on a stereo and the game developer held the Mac microphone in front of the speakers.
  25.  
  26. ETHICS ALERT!!! IF YOU FIND ETHICS OFFENSIVE, DO NOT READ THE FOLLOWING PARAGRAPH!
  27.  
  28. Well, I‚Äôm not going to get heavy into the ethical issue here, but the issue exists, and I personally resist paying someone for content stolen from someone else. I‚Äôm tolerant of little snatches snipped from hither and yon (and so is the music industry, as demonstrated on your local rap music station), as per the copyright doctrine of Fair Use, but taking somebody‚Äôs performance and song as content for your own game is Going Too Far. The pros either license music, hire a music developer, or compose their own music in-house. If I hear the theme from The X-Files (or even The Twilight Zone) playing as background music, there‚Äôd better be a licensing notice attached, or I‚Äôll be deeply unmoved by insistence that I demonstrate my personal integrity by mailing money to the game developer. And now, back to programming issues, which are already in progress‚Ķ
  29.  
  30. Once you‚Äôve chosen your music content, you‚Äôve got to get it on your game. There are four basic ways you can do this.
  31.  
  32. Many big publishers prefer CD-ROM games with streaming audio. This technique offers fabulous sound quality and long, complicated background music, but interferes with other data transfer. If a streaming audio background is playing (possibly in conjunction with a QuickTime movie), the next level isn‚Äôt loading, so streaming audio can slow down gameplay.
  33.  
  34. For major publishers, streaming audio has one big benefit: since it demands huge files (around 2-1/2 meg per minute) and since CDs are cheap to manufacture and have lots of room, streaming audio provides some brute ‚Äî force copy protection. Go ahead, put on half an hour of music ‚Äî it won‚Äôt increase the cost of pressing the CD, and 75 megabytes of music will surely deter those loathsome pirates from dragging your entire game onto their hard disks. If you‚Äôre doing a CD-ROM game, this is an avenue well worth investigating.
  35.  
  36. MIDI is gaining popularity, though more with multimedia than true games, because it provides a whole lot of music from teensy little files, and since a MIDI player is built into QuickTime, MIDI is relatively easy to implement (okay, relatively easy ‚Äî may I refer you yet again to Tricks of the Mac Game Programming Gurus, ¬©1995 Hayden Books for explanatory text, and tools on the CD in the back of the book). The disadvantage is a limited range of instruments and one instrument per channel. ‚ÄúLimited‚Äù is a relative term too, and along with the usual bagpipes and glockenspiel, you get gunshots and bird chirps and a variety of arcane tone-producing devices. For many music projects, QuickTime MIDI is more than sufficient.
  37.  
  38. The third technique is to put the whole song in a ‚Äòsnd‚Äô file. This used to be popular with floppy disk commercial games, and still shows up in a lot of shareware. Unfortunately, this technique hogs storage space and RAM, and any compromises made for space will compromise sound quality.
  39.  
  40. Voice doesn‚Äôt demand a lot of tone quality, and if your speaking game characters are robots, air traffic controllers, or cowboys who spend a lot of their time smoking those little cigars, 8-bit sound at 5.5 khz sample rate will do just fine. But if you want music, 8-bit at 22 khz is about the minimum the ear will accept. That works out to one minute of music on one 1.4 meg floppy. That doesn‚Äôt leave much space for the game, does it?
  41.  
  42. The fourth technique is the subject of this month‚Äôs column; it‚Äôs called sequencing. It involves breaking music down into little pieces for storage, and letting the program reassemble those pieces for playback. It‚Äôs rather the way that speech works (or speech programs), by taking a few dozen distinctive sounds and stringing them together into words, then stringing the words together into sentences‚Ķ
  43.  
  44. Remember when you first started noodling around on the guitar, and discovered that 90 percent of popular music could be played with just three chords? Most music is embarrassingly repetitive. Background music is particularly simple stuff; we‚Äôre not playing the New World Symphony here, we don‚Äôt want music so complex and fascinating as to distract from the game. A couple dozen four-beat bars can be assembled in enough different ways to keep the game player unaware of hearing things which were heard before.
  45.  
  46. The best real-life example is John Calhoun‚Äôs Glider Pro, published by Casady & Greene. It‚Äôs a good example because it has pleasant and hummable background music, and because it goes on and on without repeating itself, and it‚Äôs a great example because John is a straightforward guy who doesn‚Äôt hide his talents behind custom resource types. You can open Glider Pro with ResEdit or Resourcerer, and you‚Äôll find the ‚Äòsnd‚Äô files laid out in front of you. Along with the usual bangs and kablooeys you‚Äôd expect to find in a game, you‚Äôll find a number of music snippets. If you play them one at a time, they don‚Äôt sound like much, but assembled together (with some of the snippets played just once or twice, but with many snippets played many times in many different orders) they provide a catchy little tune ‚Äî a tune which is long enough that when it repeats, it seems friendly and familiar instead of oh-no-here-we-go-again.
  47.  
  48. To show the basics of sequencing, we‚Äôre going to dust off the clams again. ClamMusic and ClamMusicBig are identical to HelloWorld6 (which you‚Äôve grown to know and love over the last couple months), with the addition of some startup music.
  49.  
  50. The music is InfoHighway1, which is a sample from Optical Media International‚Äôs audio capture software for CD-ROM drives, Disc-To-Disk. It‚Äôs a very useful program for us game developers. You load an audio CD in your CD-ROM drive, Disc-To-Disk asks you which track you want to capture, what sample rate, what file format you want (including ‚Äòsnd‚Äô files, among many others), and whether you want 8- or 16-bit sound. Click ‚Äúsave‚Äù and voil√°! Music on your Mac, ready to install in your own programs.
  51.  
  52. Of course, some people won‚Äôt be able to resist using Disc-To-Disk to make Eric Clapton the background guitarist for their upcoming remake of Missile Command, but that‚Äôs not really what it‚Äôs for. Most licensable music comes on audio CDs, and if you look in the back of a multimedia magazine, you‚Äôll find ads from a veritable plethora of music content providers. They offer entire albums full of 30 second to three minute music beds and cues, described in such commercial music terminology as, ‚ÄúMedium tempo groove with laid-back rock drums," and, ‚ÄúFast-paced music bed with strings and rhythm section.‚Äù The licensing agreements generally give you non-exclusive rights to use the music in your own product, providing your product isn‚Äôt another sound or music library, and the fees are commonly in two digits ($10 to $99).
  53. The fee for InfoHighway1 (‚ÄúComputer-techno rhythmic bed with whooshes and streaks‚Äù) is included with the purchase of Disc-To-Disk, so no fair snagging it off ClamMusicBig for your own game unless you‚Äôre an Optical Media International customer.
  54.  
  55. ClamMusicBig adds the entire InfoHighway1 track to the HelloWorld resource file as ‚Äòsnd‚Äô resource #4000. It is saved in 8-bit 22 khz format to keep it from getting too out of hand, but it‚Äôs still 727,692 bytes. The ClamMusicBig application has grown from HelloWorld6‚Äôs 213k to 924k, which seems excessive to me for the addition of a half-minute computer-techno rhythmic bed, even allowing for the whooshes and streaks.
  56.  
  57. Still, it was an awfully easy piece of programming. I added‚Ķ
  58.  
  59. #define  rMusicSndID    4000
  60. ‚Ķto the declarations, commented out the previous background sound‚Ķ
  61. PlayASound(rFootstepSndID, kLowSoundPriority);
  62. ‚Ķfrom ClemLoop(), and added‚Ķ
  63. PlayASound(rMusicSndID, kLowestSoundPriority);
  64. ‚Ķright after the InitAll() call in the main function. It sure was easy, and it merely quadrupled the size of the application.
  65. ClamMusic is a bit more complex, but only a bit. Instead of one huge ‚Äòsnd‚Äô resource for the music, it has seven little ones, numbered‚Ķ
  66. #define  rDown1SndID    4001
  67. #define  rDown2SndID    4002
  68. #define  rMedium1SndID    4003
  69. #define  rMedium2SndID    4004
  70. #define  rUp1SndID     4005
  71. #define  rUp2SndID     4006
  72. #define  rFade1SndID    4007
  73.  
  74. ‚Ķeach around 19k, four beats, and .866 seconds long. I‚Äôll admit there was some trial and error involved in coming up with the .866 second figure. I used Macromedia‚Äôs SoundEdit Pro to pick the InfoHighway1 file apart, and relied heavily on the visual feature (the spikes that showed up when individual instruments went dit-dit-dit) to measure and time what four beats were, but still there were a couple hours of cut-and-paste before I got satisfactory results. Satisfactory to me, that is; if you‚Äôre not up at 3 a.m., your satisfaction may demand higher artistic standards.
  75.  
  76. So here we have a couple of music snippets that go down, and a couple that go up, and a couple that don‚Äôt change much in pitch from beginning to end, and one that is quieter than the rest. And we have some new functions, named‚Ķ
  77.  
  78. void DoBackgroundMusic0(void);
  79. void DoBackgroundMusic1 (void);
  80. void DoBackgroundMusic2 (void);
  81. void DoBackgroundMusic3 (void);
  82. void DoBackgroundFadeOut (void);
  83.  ‚Ķof which DoBackgroundMusic0() is typical:
  84. void DoBackgroundMusic0 (void)
  85. {
  86.  AddSoundToQ(rFade1SndID);
  87.  AddSoundToQ(rFade1SndID);
  88.  AddSoundToQ(rFade1SndID);
  89.  AddSoundToQ(rMedium1SndID);
  90.  AddSoundToQ(rUp2SndID);
  91.  AddSoundToQ(rMedium1SndID);
  92.  AddSoundToQ(rMedium2SndID);
  93.  AddSoundToQ(rDown1SndID);
  94.  AddSoundToQ(rMedium1SndID);
  95.  AddSoundToQ(rMedium2SndID);
  96. }
  97. Collecting all these stanzas together, we have‚Ķ
  98. void DoBackgroundMusic (void)
  99. {
  100.  DoBackgroundMusic0();
  101.  DoBackgroundMusic1();
  102.  DoBackgroundMusic2();
  103.  DoBackgroundMusic3();
  104.  DoBackgroundMusic2();
  105.  DoBackgroundMusic1();
  106.  DoBackgroundMusic1();
  107.  DoBackgroundMusic2();
  108.  DoBackgroundFadeOut();
  109. }
  110. ‚Ķright after the InitAll() call in the main function. Sound familiar?
  111.  
  112. All in all, ClamMusic makes about 90 calls to AddSoundToQ() (a Feeping Creatures routine from MGWSound.c), which stacks up all those music snippets and plays them in order. Thus we get 90 four-beat bars of music, with only seven four-beat bars worth of storage. I think when you run the ClamMusic application, you‚Äôll find it captures the feel of InfoHighway quite nicely‚Äîthough it‚Äôs admittedly weak regarding hummability‚Äîand the application size on disk is only 345k.
  113.  
  114. The code and resources are in the Code Folder, along with CodeWarrior 68K C projects for you Metrowerks users. For Disk-To-Disk sales information, call Optical Media International at 800-347-2664 (it costs around a hundred bucks). Nope, I‚Äôm not connected with them, I'm just a satisfied user. If you have questions about this column (or ideas for it, or a product you feel would be appropriate for review) you can find me at MacGameDev on AOL (that‚Äôs macgamedev@aol.com from other services).